package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.core.AreaService;
import com.fwtai.service.web.StoreService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 门店控制层|路由层
 * @作者 李宇鹏
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2023-03-13 16:30:23
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/store")
public class StoreController{

  private final StoreService storeService;

  private final AreaService areaService;

  public StoreController(final StoreService storeService,final AreaService areaService){
    this.storeService = storeService;
    this.areaService = areaService;
  }

  /**添加*/
  @PreAuthorize("hasAuthority('store_manage_btn_add')")
  @PostMapping("/add")
  public void add(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(storeService.add(request),response);
  }

  /**行内编辑*/
  @PreAuthorize("hasAuthority('store_manage_row_edit')")
  @PostMapping("/edit")
  public void edit(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(storeService.edit(request),response);
  }

  /**审核（行内）*/
  @PreAuthorize("hasAuthority('store_manage_row_auth')")
  @PostMapping("/editAuth")
  public void editAuth(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(storeService.editAuth(request),response);
  }

  /**根据id查询对应的数据*/
  @PreAuthorize("hasAuthority('store_manage_row_queryById')")
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(storeService.queryById(id),response);
  }

  /**删除-单行*/
  @PreAuthorize("hasAuthority('store_manage_row_delById')")
  @PostMapping("/delById")
  public void delById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(storeService.delById(id),response);
  }

  /**批量删除*/
  @PreAuthorize("hasAuthority('store_manage_btn_delByKeys')")
  @PostMapping("/delByKeys")
  public void delByKeys(final String ids,final HttpServletResponse response){
    ToolClient.responseJson(storeService.delByKeys(ids),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('store_manage_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(storeService.listData(new PageFormData(request)),response);
  }

  @PreAuthorize("hasAuthority('store_br_getListArea')")//新增或编辑同时都使用的标识
  @GetMapping("/getListArea")
  public void getListArea(final String pid,final String selected,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(areaService.getListArea(pid,selected,request),response);
  }
}